Skip to content

feat(sheets): add +undo shortcut for AI-tool edits#1321

Open
zhengzhijiej-tech wants to merge 5 commits into
feat/lark-sheets-developfrom
feat-undo-last-zzj
Open

feat(sheets): add +undo shortcut for AI-tool edits#1321
zhengzhijiej-tech wants to merge 5 commits into
feat/lark-sheets-developfrom
feat-undo-last-zzj

Conversation

@zhengzhijiej-tech

Copy link
Copy Markdown
Collaborator

What

Add a token-scoped +undo shortcut that reverses recent sheet edits made through the sheet-ai write tools, by invoking the undo_last write tool.

  • +undo [--steps N | --op NAME]: undo the last N steps, or a named operation
  • Thread a session-stable transaction id (LARK_CLI_SHEET_TRANSACTION_ID) into the tool request's extra.transaction_id, so a group of edits and a later +undo share one server-side undo stack; omitted when unset to preserve per-request behavior
  • flag-defs + generated defs for the new shortcut

Why

Lets an agent driving lark-cli undo a group of AI-tool sheet edits in one call, rather than manually reconstructing prior state.

Notes

Depends on the backend undo_last write tool (byted-sheet) + facade registration (sheet-facade-agg). The backend reverse-changeset path is still being finalized; the CLI side here is self-contained and gated by the transaction-id env var.

Add a token-scoped +undo shortcut that reverses recent sheet edits made
through the sheet-ai write tools, by invoking the undo_last write tool.

- +undo [--steps N | --op NAME]: undo the last N steps, or a named op
- thread a session-stable transaction id (LARK_CLI_SHEET_TRANSACTION_ID)
  into the tool request's extra.transaction_id, so a group of edits and a
  later +undo share one server-side undo stack; omitted when unset to
  preserve per-request behavior
- flag-defs + generated defs for the new shortcut
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cdae26f1-cf38-45e1-bbbf-9cca864f5691

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-undo-last-zzj

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Jun 8, 2026
buildToolBody attached extra.transaction_id to every tool invocation,
including read tools (get_cell_ranges, get_range_as_csv, search_data,
get_workbook_structure, ...). A read scoped to a transaction id resolves
against that transaction's snapshot instead of the live document, so
reads returned blank cells whenever LARK_CLI_SHEET_TRANSACTION_ID was
set. Gate the extra block to ToolKindWrite — the undo stack only ever
concerns writes — by threading kind into buildToolBody at every call
site. Adds a regression test that read tools omit the transaction id.
+recover --to-revision N rolls the whole spreadsheet back to a past
revision via the recover_to_revision write tool (facade reuses its
existing ProcessRecoverCs / revert-by-revision path). Distinct from
+undo, which is precise and this-link-only; +recover is a full-document
restore that discards all later edits, so it carries no sheet selector
and a prominent overwrite warning in --help.

Adds the +recover flag-defs entry (url / spreadsheet-token / to-revision)
to both data/flag-defs.json and the compiled flag_defs_gen.go.
@github-actions github-actions Bot added size/L Large or sensitive change across domains or core paths and removed size/M Single-domain feat or fix with limited business impact labels Jun 9, 2026
Without LARK_CLI_SHEET_TRANSACTION_ID set, every CLI write received a fresh
server-minted transaction id, so a group of edits and a later +undo never
shared an undo stack and +undo could not reach the prior writes.

Resolve the write tool's extra.transaction_id in three tiers:
  1. $LARK_CLI_SHEET_TRANSACTION_ID — explicit caller override.
  2. else a value derived from the OS session (getsid on unix, falling back
     to the parent pid; salted with uid and boot/host) so edits in one shell
     session group by default, with no env var to set. Each invocation is a
     fresh process and recomputes the same id rather than persisting one.
  3. else "" — the server mints a per-request id as before.

The derivation never needs the spreadsheet token (undo read-back is already
keyed by token + transaction id), so buildToolBody keeps its signature and
reads still never carry the id.
The stdlib syscall package exposes Getsid on darwin/BSD but not on linux,
so the session-id derivation broke linux cross-compilation. Switch to
golang.org/x/sys/unix.Getsid (already a direct dependency), and narrow the
build tag from !windows to unix to match where that package is available.
Verified all six release targets (darwin/linux/windows x amd64/arm64) build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant